//
//  LYLoanTipsController.swift
//  LYOnlineBanking
//
//  Created by 李永彬 on 2025/7/26.
//

import UIKit

class LYLoanTipsController: LYBaseViewController {
    
    private let scrollView = UIScrollView()
    private let contentView = UIView()
    
    private lazy var checkCreditImageView: UIImageView = {
        let iv = UIImageView()
        iv.contentMode = .scaleAspectFit
        iv.image = UIImage(named: "check_credit_report_bg")
        return iv
    }()
    
    private lazy var checkCreditButton: UIButton = {
        let button = UIButton()
        button.addTarget(self, action: #selector(checkCreditButtonAction(_:)), for: .touchUpInside)
        return button
    }()
    
    private lazy var timelyImageView: UIImageView = {
        let iv = UIImageView()
        iv.contentMode = .scaleAspectFit
        iv.image = UIImage(named: "timely_repayment_bg")
        return iv
    }()
    
    private lazy var timelyButton: UIButton = {
        let button = UIButton()
        button.addTarget(self, action: #selector(timelyButtonAction(_:)), for: .touchUpInside)
        return button
    }()
    
    private lazy var onlineLoanImageView: UIImageView = {
        let iv = UIImageView()
        iv.contentMode = .scaleAspectFit
        iv.image = UIImage(named: "online_loan_bg")
        return iv
    }()
    
    private lazy var onlineLoanButton: UIButton = {
        let button = UIButton()
        button.addTarget(self, action: #selector(onlineLoanButtonAction(_:)), for: .touchUpInside)
        return button
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.view.backgroundColor = UIColor(hex: "#FC7900")
        self.title = LYlocalizedString("LoanTips")
        commonInitSubviews()
    }
    
    func commonInitSubviews() {
    
        self.view.addSubview(scrollView)
        scrollView.addSubview(contentView)
        contentView.addSubview(checkCreditImageView)
        contentView.addSubview(checkCreditButton)
        contentView.addSubview(timelyImageView)
        contentView.addSubview(timelyButton)
        contentView.addSubview(onlineLoanImageView)
        contentView.addSubview(onlineLoanButton)
        
        scrollView.snp.makeConstraints { make in
            make.top.equalTo(view.safeAreaLayoutGuide.snp.top).offset(0)
            make.leading.trailing.bottom.equalToSuperview()
        }
        
        contentView.snp.makeConstraints { make in
            make.top.leading.trailing.equalToSuperview()
            make.width.equalTo(scrollView)
        }
        
        let creditRatio = 191.0 / 338.0
        let creditLeft = 15.0
        let creditWidth = SCREEN_WIDTH - creditLeft * 2
        let creditHeight = creditWidth * creditRatio
        
        checkCreditImageView.snp.makeConstraints { make in
            make.width.equalTo(creditWidth)
            make.height.equalTo(creditHeight)
            make.top.equalToSuperview().offset(20)
            make.centerX.equalToSuperview()
        }
        
        checkCreditButton.snp.makeConstraints { make in
            make.edges.equalTo(checkCreditImageView)
        }
        
        let timelyRatio = 196.0 / 338.0
        let timelyLeft = 15.0
        let timelyWidth = SCREEN_WIDTH - timelyLeft * 2
        let timelyHeight = timelyWidth * timelyRatio
        
        timelyImageView.snp.makeConstraints { make in
            make.width.equalTo(timelyWidth)
            make.height.equalTo(timelyHeight)
            make.top.equalTo(checkCreditImageView.snp.bottom).offset(20)
            make.centerX.equalToSuperview()
        }
        
        timelyButton.snp.makeConstraints { make in
            make.edges.equalTo(timelyImageView)
        }
        
        let onlineRatio = 196.0 / 338.0
        let onlineLeft = 15.0
        let onlineWidth = SCREEN_WIDTH - onlineLeft * 2
        let onlineHeight = onlineWidth * onlineRatio
        onlineLoanImageView.snp.makeConstraints { make in
            make.width.equalTo(onlineWidth)
            make.height.equalTo(onlineHeight)
            make.top.equalTo(timelyImageView.snp.bottom).offset(20)
            make.centerX.equalToSuperview()
        }
        
        onlineLoanButton.snp.makeConstraints { make in
            make.edges.equalTo(onlineLoanImageView)
            make.bottom.equalToSuperview()
        }
        
        self.view.layoutIfNeeded()
        scrollView.contentSize = contentView.frame.size
    }
    
    @objc func checkCreditButtonAction(_ sender: UIButton) {
        
    }
    
    @objc func timelyButtonAction(_ sender: UIButton) {
        
    }
    
    @objc func onlineLoanButtonAction(_ sender: UIButton) {
        
    }
}

